//
//  WYCommetNormolCell.m
//  Boss
//
//  Created by admin on 2018/8/6.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYCommetNormolCell.h"
#import <YYText/YYText.h>
@interface WYCommetNormolCell()

@property (strong, nonatomic) IBOutlet UIImageView *userImageView;
@property (strong, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) IBOutlet UILabel *timeLabel;
@property (strong, nonatomic) IBOutlet UILabel *contentLabel;
@property (strong, nonatomic) IBOutlet UIButton *deleteBtn;

@property (strong, nonatomic) IBOutlet UIImageView *vipImageView;

@end
@implementation WYCommetNormolCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.userImageView setCornerRadius:20.f];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setList:(WYReplyList *)list
{
    _list = list;
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:list.fromUserPhoto] placeholderImage:[UIImage imageNamed:@"ic_defult_avatar"]];
    self.nameLabel.text = list.fromUserName;
    self.timeLabel.text = [NSString compareCurrentTime:list.replyTime];
    
    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    if ([userMessage.id isEqualToString:list.fromUserId]) {
        self.deleteBtn.hidden = NO;
    }else{
        self.deleteBtn.hidden = YES;
    }
    
    [self.vipImageView showVipImageViewStatusWithVipId:list.fromUserVipLevel];
    
    if ([list.toReplyId isEqualToString:@"0"]) {
        self.contentLabel.text = list.content;
    }else{
        NSString *str = [NSString stringWithFormat:@"回复 %@: %@ ",list.toUserName,list.content];
        
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:str];
        //        [attributedString addAttribute:NSForegroundColorAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, attributedString.length)];
        
        
        [attributedString yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attributedString.length)];
        
        NSString *string = [NSString stringWithFormat:@"回复 %@:",list.toUserName];
        NSRange searchRange = NSMakeRange(0, attributedString.string.length);
        NSRange range = [attributedString.string rangeOfString:string options:kNilOptions range:searchRange];
        if (range.location == NSNotFound) return;
        if ([attributedString yy_attribute:YYTextHighlightAttributeName atIndex:range.location] == nil) {
            [attributedString yy_setColor:[UIColor hexStringToColor:@"#527ead" alpha:1.0] range:range];
            
            // 高亮状态
            YYTextHighlight *highlight = [YYTextHighlight new];
            //[highlight setBackgroundBorder:highlightBorder];
            // 数据信息，用于稍后用户点击
            //  highlight.userInfo = @{kWBLinkTopicName : topic};
            [attributedString yy_setTextHighlight:highlight range:range];
        }
        
        self.contentLabel.attributedText = attributedString;
        
        
        
    }
    
    
}
- (IBAction)deleteAction:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(didDeleteButtonWithReplyId:)]) {
        [self.delegate didDeleteButtonWithReplyId:self.list.replyId];
    }
    
    
}







@end
